package com.itheima;

public class TestLambda {
    public static void main(String[] args) {
        testA();
        testB();
        testC();
        testD();
    }

    public static void testC(){
        //创建C接口的匿名内部类对象
        C c1 = new C() {
            @Override
            public String show(String name) {
                return "name = " + name;
            }
        };
        //创建C接口的Lambda表达式对象
        C c2 = name -> "name = " + name;
        //创建C接口的方法引用对象
        C c3 = TestLambda::show4;
        String s = c3.show("丁真");
        System.out.println(s);





    }

    public static String show4(String name){
        return "name = " + name;
    }

    public static void testD(){
        D d1 = new D() {
            @Override
            public int max(int a, int b) {
                return Math.max(a, b);
            }
        };

        D d2 = (a, b) -> a > b ? a : b;

        D d3 = Math::max;
        d3.max(10, 20);
        System.out.println(d3.max(10, 20));
    }


    public static void testA() {
        A a1 = new A() {
            @Override
            public void show(String name, int age) {
                System.out.println(name + "," + age);
            }
        };
        //将匿名内部类对象改成Lambda表达式
        A a2 = (name, age) -> System.out.println(name + "," + age);
        a2.show("zhangsan", 18);

        //使用方法引用替换Lambda表达式
        A a3 = TestLambda::show2;
        a3.show("lisi", 20);

        //使用方法引用替换Lambda表达式（成员方法）
        TestLambda testLambda = new TestLambda();
        A a4 = TestLambda::show3;
        a4.show("wangwu", 35);
    }
    public static void testB(){
        B b1 = new B() {
            @Override
            public void show(String name) {
                System.out.println(name);

            }

        };
        //创建B接口的Lambada表达式对象
        B b2 = (name) -> System.out.println(name);

        //创建B接口的方法引用对象
        B b3 = System.out::println;
        b3.show("李明");
    }






    //定义一个成员方法，故意让返回值和形参列表和A接口中的方法一致
    public static void show2(String name,int age){
        System.out.println("show2"+name+","+age);

    }
    public static void show3(String name, int age){
        System.out.println("show2"+name+","+age);

    }
}
